/**
 * Created by zhangjinrui on 17/6/27.
 */
public class Solution328Good {

    public static void main(String args[]) {
        Solution328Good s = new Solution328Good();
    }

    public ListNode oddEvenList(ListNode head) {
        if(head == null){
            return null;
        }
        if(head.next == null){
            return head;
        }

        ListNode s1 = head;
        ListNode s2 = head.next;

        ListNode odd = head;
        ListNode even = head.next;

        while (even != null && even.next != null) {

            odd.next = odd.next.next;
            odd = odd.next;

            even.next = even.next.next;
            even = even.next;
        }

        odd.next = s2;
        return s1;
    }
}

class ListNode {
    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
    }

    public String toString(){
        StringBuilder sb = new StringBuilder();
        sb.append(val);
        ListNode cur = next;
        while(cur != null){
            sb.append(",").append(cur.val);
            cur = cur.next;
        }
        return sb.toString();
    }
}
